﻿<!--
	This software known as 'Distrib' is under the GNU GPL v2. License
		This license can be found at: http://www.gnu.org/licenses/gpl-2.0.html

	Unless this software has been made available to you under the terms of an alternative license by
	Clint Pearson, your use of this software is dependent upon compliance with the GNU GPL v2. license.

	This software is the sole copyright of Clint Pearson
		Contact: clintkpearson@gmail.com

	This software is provided with NO WARRANTY at all, explicit or implied.

	If you wish to contact me about the software / licensing you can reach me at distribgrid@gmail.com
-->
<UserControl x:Class="ProcessRunner.Views.PluginsInvestigatorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:metro="http://schemas.codeplex.com/elysium"
             xmlns:conv="clr-namespace:ProcessRunner.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="800">
    <Grid>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
            <ItemsControl ItemsSource="{Binding Plugins}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,10,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="470">
                            <Grid.Resources>
                                <SolidColorBrush x:Key="usableBrush" Color="Green" />
                                <SolidColorBrush x:Key="notUsableBrush" Color="Red" />
                                <conv:StringPrependConverter x:Key="prependConv" />
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Orientation="Vertical" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                                <Border CornerRadius="3" Width="24" Height="24" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <Border.Style>
                                        <Style TargetType="Border">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsUsable}" Value="True">
                                                    <Setter Property="Background" Value="{StaticResource usableBrush}" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding IsUsable}" Value="False">
                                                    <Setter Property="Background" Value="{StaticResource notUsableBrush}" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Border.Style>
                                </Border>

                                <TextBlock TextWrapping="Wrap" Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Bottom">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsUsable}" Value="True">
                                                    <Setter Property="Text" Value="Usable" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding IsUsable}" Value="False">
                                                    <Setter Property="Text" 
                                                        Value="Excluded" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </StackPanel>

                            <Grid Grid.Column="1" Background="DimGray" Width="1" Margin="10,0,0,0">
                                <Grid.OpacityMask>
                                    <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                                        <GradientStop Offset="0" Color="Transparent" />
                                        <GradientStop Offset=".4" Color="Black" />
                                        <GradientStop Offset=".6" Color="Black" />
                                        <GradientStop Offset="1" Color="Transparent" />
                                    </LinearGradientBrush>
                                </Grid.OpacityMask>
                            </Grid>

                            <Grid Grid.Column="2" Margin="10,0,0,0">
                                <Grid.Resources>
                                    <Style x:Key="propertyLabel" TargetType="Label">
                                        <Setter Property="FontSize" Value="14" />
                                        <Setter Property="HorizontalAlignment" Value="Right" />
                                        <Setter Property="VerticalAlignment" Value="Center" />
                                    </Style>

                                    <Style x:Key="boundPropertyLabel" TargetType="Label">
                                        <Setter Property="FontSize" Value="14" />
                                        <Setter Property="FontStyle" Value="Italic" />
                                        <Setter Property="HorizontalAlignment" Value="Left" />
                                        <Setter Property="VerticalAlignment" Value="Center" />
                                    </Style>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Style="{StaticResource propertyLabel}"
                                   Content="Type Name:" />

                                <Label Grid.Column="1" Grid.Row="0" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock Text="{Binding TypeName}" TextWrapping="Wrap" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="1" Style="{StaticResource propertyLabel}"
                                   Content="Exclusion Reason:" />

                                <Label Grid.Column="1" Grid.Row="1" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock>
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsUsable}" Value="True">
                                                        <Setter Property="Text" Value="Plugin not excluded" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding IsUsable}" Value="False">
                                                        <Setter Property="Text" 
                                                        Value="{Binding ExclusionReason}" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </Label>

                                <Label Grid.Column="0" Grid.Row="2" Style="{StaticResource propertyLabel}"
                                   Content="Name:" />
                                <Label Grid.Column="1" Grid.Row="2" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock TextWrapping="Wrap" Text="{Binding PluginName}" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="3" Style="{StaticResource propertyLabel}"
                                       Content="Description:" />

                                <Label Grid.Column="1" Grid.Row="3" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock Text="{Binding PluginDescription}" TextWrapping="Wrap" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="4" Style="{StaticResource propertyLabel}"
                                       Content="Author:" />
                                <Label Grid.Column="1" Grid.Row="4" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock Text="{Binding PluginAuthor}" TextWrapping="Wrap" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="5" Style="{StaticResource propertyLabel}"
                                       Content="Version:" />
                                <Label Grid.Column="1" Grid.Row="5" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock TextWrapping="Wrap" Text="{Binding PluginVersion}" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="6" Style="{StaticResource propertyLabel}"
                                       Content="Interface:" />
                                <Label Grid.Column="1" Grid.Row="6" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock TextWrapping="Wrap" Text="{Binding PluginInterface}" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="7" Style="{StaticResource propertyLabel}"
                                       Content="Controller:" />
                                <Label Grid.Column="1" Grid.Row="7" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock TextWrapping="Wrap" Text="{Binding PluginController}" />
                                </Label>

                                <Label Grid.Column="0" Grid.Row="8" Style="{StaticResource propertyLabel}"
                                       Content="Identifier:" />
                                <Label Grid.Column="1" Grid.Row="8" Style="{StaticResource boundPropertyLabel}">
                                    <TextBlock Text="{Binding PluginIdentifier}" TextWrapping="Wrap" />
                                </Label>

                                <GroupBox Margin="5" HorizontalAlignment="Stretch" Header="Additional Metadata" Grid.ColumnSpan="2" Grid.Row="9">
                                    <ItemsControl ItemsSource="{Binding AdditionalMetadata}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>

                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>

                                                    <Label Grid.Column="0" Grid.Row="0" Style="{StaticResource propertyLabel}"
                                                           Content="Bundle Identity:" />
                                                    <Label Grid.Column="1" Grid.Row="0" Style="{StaticResource boundPropertyLabel}">
                                                        <TextBlock TextWrapping="Wrap" Text="{Binding MetadataBundleIdentity}" />
                                                    </Label>

                                                    <Label Grid.Column="0" Grid.Row="1" Style="{StaticResource propertyLabel}"
                                                           Content="Existence Policy:" />
                                                    <Label Grid.Column="1" Grid.Row="1" Style="{StaticResource boundPropertyLabel}">
                                                        <TextBlock TextWrapping="Wrap" Text="{Binding MetadataInstanceExistencePolicy}" />
                                                    </Label>

                                                    <GroupBox Header="KVPs" Grid.ColumnSpan="2" Grid.Row="2">
                                                        <ItemsControl ItemsSource="{Binding MetadataKVPs}">
                                                            <ItemsControl.ItemTemplate>
                                                                <DataTemplate>
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition Width="100" />
                                                                            <ColumnDefinition Width="*" />
                                                                        </Grid.ColumnDefinitions>

                                                                        <Label FontSize="12" Style="{StaticResource propertyLabel}" Content="{Binding Key}" Grid.Column="0"
                                                                                               HorizontalAlignment="Right"
                                                                                               VerticalAlignment="Center" />

                                                                        <Label FontSize="12" Style="{StaticResource boundPropertyLabel}" Grid.Column="1"
                                                                                               HorizontalAlignment="Left"
                                                                                               VerticalAlignment="Center">
                                                                            <TextBlock TextWrapping="Wrap" Text="{Binding Value}" />
                                                                        </Label>
                                                                    </Grid>
                                                                </DataTemplate>
                                                            </ItemsControl.ItemTemplate>
                                                        </ItemsControl>
                                                    </GroupBox>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </GroupBox>
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
</UserControl>
